package com.bright.cwduijie.duijie.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.lang.Nullable;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * @Author hxj
 * @Date 2024/7/9 11:19
 * @Description
 */

@Getter
@AllArgsConstructor
public enum DataApi {

    /**
     *
     */
    ACC_SET("W01001", "账套数据", "DJ_ZTXX"),
    ASSIST_CODE_TYPE("W01101", "写入辅助核算项目类型数据", "DJ_FZHSLX"),
    ACC_CODE("W01002", "账套科目初始化", "DJ_KMCSHSJ"),
    ASSIST_CODE("W01102", "辅助核算项目", "DJ_FZHSXM"),
    VOUCHER("W01003", "会计凭证数据", "DJ_PZM"),
    MONTHLY_SETTLEMENT("W01004", "账套月结", "DJ_ZTYJ"),
    FIXED_ASSETS_INFO_CHANGE("W01006", "固定资产-信息变更", "DJ_GDZC_XXBG"),
    FIXED_ASSETS_VALUE_CHANGE("W01007", "固定资产-价值变动", "DJ_GDZC_JZBG"),
    FIXED_ASSETS_HANDLE_LOG("W01008", "固定资产-处置记录", "DJ_GDZC_CZ"),
    FIXED_ASSETS_DEPRECIATION_LOG("W01009", "固定资产-折旧记录", "DJ_GDZC_ZJ"),
    BALANCE("W01010", "资产负债表", "DJ_ZCFZB"),
    DEBT_PUBLISH("W01011", "债务公布", "DJ_ZWGBB"),
    CREDIT_PUBLISH("W01012", "债权公布", "DJ_ZQGBB"),
    FIXED_ASSETS("W02001", "固定资产", "DJ_GDZC"),
    DAY_BOOKS("W04001", "收支日记账", "DJ_SZRJZ"),
    CONTRACT("W03001", "合同信息", "DJ_HTXX"),
    CUSTOM_ASSET_CODE("W02101", "自定义资产分类", "DJ_ZDYZCFL"),
    BIO_ASSETS("W02002", "写入生物资产", "DJ_SWZC"),
    INVENTORY_ASSETS("W02003", "写入存货资产", "DJ_CHZC"),
    IMMATERIAL_ASSETS("W02004", "写入无形资产", "DJ_WXZC"),
    COLLECTIVE_LAND("W02005", "写入集体土地", "DJ_JTTD"),

    DELETE_ACC_SET("D01001", "删除账套信息", "DJ_ZTXX"),
    DELETE_ASSIST_CODE_TYPE("D01101", "删除辅助核算项目类型数据", "DJ_FZHSLX"),
    DELETE_ASSIST_CODE("D01102", "删除辅助核算项目", "DJ_FZHSXM"),
    DELETE_VOUCHER("D01003", "删除会计凭证", "DJ_PZM"),
    DELETE_FIXED_ASSETS("D02001", "删除固定资产", "DJ_GDZC"),
    DELETE_DAY_BOOKS("D04001", "作废收支日记账", "DJ_SZRJZ"),
    DELETE_CONTRACT("D03001", "删除合同", "DJ_HTXX"),
    DELETE_CUSTOM_ASSET_CODE("D02101", "删除自定义资产分类编码", "DJ_ZDYZCFL"),
    DELETE_BIO_ASSETS("D02002", "删除生物资产", "DJ_SWZC"),
    DELETE_INVENTORY_ASSETS("D02003", "删除存货资产", "DJ_CHZC"),
    DELETE_IMMATERIAL_ASSETS("D02004", "删除无形资产", "DJ_WXZC"),
    DELETE_COLLECTIVE_LAND("D02005", "删除集体土地", "DJ_JTTD"),



    // ========== 附件上传 ==========
    F01003("F01003", "新增会计凭证附件", "DJ_FILE"),
    F02001("F02001", "新增固定资产附件", "DJ_FILE"),
    F02002("F02002", "新增生物资产附件", "DJ_FILE"),
    F02003("F02003", "新增存货资产附件", "DJ_FILE"),
    F02004("F02004", "新增无形资产附件", "DJ_FILE"),
    F02005("F02005", "新增集体土地附件", "DJ_FILE"),
    F03001("F03001", "新增合同附件", "DJ_FILE"),
    F03002("F03002", "新增合同收款附件", "DJ_FILE"),
    F03003("F03003", "新增合同付款附件", "DJ_FILE"),
    F04001("F04001", "新增收支日记账附件", "DJ_FILE"),

    // ========== 删除附件 ==========
    DF1003("DF1003", "删除会计凭证附件", "DJ_FILE"),
    DF2001("DF2001", "删除固定资产附件", "DJ_FILE"),
    DF2002("DF2002", "删除生物资产附件", "DJ_FILE"),
    DF2003("DF2003", "删除存货资产附件", "DJ_FILE"),
    DF2004("DF2004", "删除无形资产附件", "DJ_FILE"),
    DF2005("DF2005", "删除集体土地附件", "DJ_FILE"),
    DF3001("DF3001", "删除合同附件", "DJ_FILE"),
    DF3002("DF3002", "删除合同收款附件", "DJ_FILE"),
    DF3003("DF3003", "删除合同付款附件", "DJ_FILE"),
    DF4001("DF4001", "删除收支日记账附件", "DJ_FILE"),

    QUERY_TASK("Q99001", "查询异步任务进度", null),


    /*测试用*/
    // ========== 财务基础数据 ==========
    W01001("W01001", "写入农村集体经济组织账套数据", "TEST"),
    W01002("W01002", "写入账套科目初始化数据", "TEST"),
    W01101("W01101", "写入辅助核算项目类型数据", "TEST"),
    W01102("W01102", "辅助核算项目", "TEST"),


    // ========== 财务业务数据 ==========
    W01003("W01003", "写入会计凭证数据", "TEST"),
    W01004("W01004", "写入账套月结", "TEST"),
    W01006("W01006", "写入固定资产-信息变更记录", "TEST"),
    W01007("W01007", "写入固定资产-价值变更记录", "TEST"),
    W01008("W01008", "写入固定资产-处置记录", "TEST"),
    W01009("W01009", "写入固定资产-折旧记录", "TEST"),
    W01010("W01010", "写入资产负债表", "TEST"),
    W01011("W01011", "写入债务公布表", "TEST"),
    W01012("W01012", "写入债权公布表", "TEST"),


    // ========== 资金管理业务数据 ==========
    W04001("W04001", "写入收支日记账信息", "TEST"),


    // ========== 合同业务数据 ==========
    W03001("W03001", "写入合同信息", "TEST"),


    // ========== 资产管理业务数据 ==========
    W02101("W02101", "自定义资产分类编码数据", "TEST"),
    W02001("W02001", "写入固定资产", "TEST"),
    W02002("W02002", "写入生物资产", "TEST"),
    W02003("W02003", "写入存货资产", "TEST"),
    W02004("W02004", "写入无形资产", "TEST"),
    W02005("W02005", "写入集体土地", "TEST"),


    // ========== 数据删除 ==========
    D01001("D01001", "删除账套数据", "TEST"),
    D01101("D01101", "删除辅助核算项目类型数据", "TEST"),
    D01102("D01102", "删除辅助核算项目数据", "TEST"),
    D02101("D02101", "删除自定义资产分类编码数据", "TEST"),
    D01003("D01003", "删除会计凭证", "DJ_FILE"),
    D02001("D02001", "删除固定资产数据", "DJ_FILE"),
    D02002("D02002", "删除生物资产", "DJ_FILE"),
    D02003("D02003", "删除存货资产", "DJ_FILE"),
    D02004("D02004", "删除无形资产", "DJ_FILE"),
    D02005("D02005", "删除集体土地", "DJ_FILE"),
    D03001("D03001", "删除合同数据", "DJ_FILE"),
    D04001("D04001", "作废收支日记账", "DJ_FILE"),
    ;


    private final String serviceCode;

    private final String description;
    // 对应实际数据表的名称 更新状态时用到
    private final String tableName;

    private final static Map<String, DataApi> API_MAP = new HashMap<>();
    static {
        for (DataApi value : values()) {
            // v1.5.9 同一个serviceCode 只用最上面定义的
            API_MAP.putIfAbsent(value.getServiceCode(), value);
        }
    }

    @Deprecated
    @Nullable
    public static DataApi of(String serviceCode) {
//        for (DataApi value : values()) {
//            if (StringUtil.equalsIgnoreCase(value.getServiceCode(), serviceCode)) {
//                return value;
//            }
//        }
//        return null;
//        if (!API_MAP.containsKey(serviceCode)) {
//            throw new ServiceCodeNotFoundExcetpion("");
//        }
        return API_MAP.get(serviceCode);
    }

    public static Optional<DataApi> ofOptional(String serviceCode) {
        return Optional.ofNullable(API_MAP.get(serviceCode));
    }

//    public static class ServiceCodeNotFoundExcetpion extends Throwable {
//        String msg;
//
//        ServiceCodeNotFoundExcetpion(String msg) {
//            this.msg = msg;
//        }
//    }


}
